import { Router } from "vue-router"
import NotFoundPage from "@/pages/NotFoundPage.vue"
import HomePage from "@/pages/HomePage.vue"
import { addIdentitiesPages } from "@/pages/identities/routes/routesInit"
import { useUniqueComponentsStore } from "../globalStores/uniqueComponents"

const titleBase = (import.meta.env.VITE_AppNameOnBrowserTab ?? "AuSys") as string

export function routerSetup(router:Router){
    addIdentitiesPages(router)

    router.addRoute({
        path: '/:pathMatch(.*)*',
        component: NotFoundPage
    })
    if(!router.options.routes.some(x=>x.path==='/')){
        router.addRoute({
            path: '/',
            component: HomePage
        })
    }
    router.beforeEach((to)=>{
        if(to.meta['topbar'] === false){
            useUniqueComponentsStore().topbarShow = false
        }else{
            useUniqueComponentsStore().topbarShow = true
        }
        if(to.meta['title']){
            const value = to.meta['title']
            document.title = `${titleBase} | ${value}`
        }else{
            document.title = titleBase
        }
    })
}
